package com.gaoqi.mq.Topics;


import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 模拟rabbitMQ topics 工作模式 消费者
 */
@Component
public class TopicsConsumer {

    @RabbitListener(bindings = {
            @QueueBinding(
                    //设置临时队列
                    value = @Queue,
                    //设置绑定交换机
                    exchange = @Exchange(value = "topics",type = "topic"),
                    //设置route key
                    key = {"user.*"}
            )
    })
    public void receive1MessageOfTopics(String message){
        System.out.println("消费者1:消费:"+message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(
                    //设置临时队列
                    value = @Queue,
                    //设置绑定交换机
                    exchange = @Exchange(value = "topics",type = "topic"),
                    //设置route key(*为任意单 通配符 # 为1-n多个任意 )
                    key = {"save.#"}
            )
    })
    public void receive2MessageOfTopics(String message){
        System.out.println("消费者2:消费:"+message);
    }
}
